package com.lgx.mall.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import net.sf.json.JSONObject;

import com.lgx.common.entity.IdGenerator;
import com.lgx.right.entity.Organization;

/**
 * 广告信息
 * @author pengdeyi
 * 
 */
@Entity
@Table(name="TM_ADVERTISEMENT")
public class Advertisement implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.TABLE,generator=IdGenerator.ADVERTISEMENT_ID_GENERATOR)
	@TableGenerator(
			name = IdGenerator.ADVERTISEMENT_ID_GENERATOR,
			table = IdGenerator.GENERATOR_TABLE,
			pkColumnName = IdGenerator.GEN_NAME,
			pkColumnValue = IdGenerator.ADVERTISEMENT_ID_GENERATOR,
			valueColumnName = IdGenerator.GEN_VALUE,
			initialValue = 1,
			allocationSize = 1
	)
	private long id;
	
	private String imageUrl;//图片路径
	
	@Column(name = "createId")
	private String createId;//创建用户
	
	private Date createTime;//创建时间
	
	private int timeLimit;//期限
	
	@ManyToOne
	@JoinColumn(name = "merchant_id")
	private Organization merchant;//广告商家
	
	private String isDelete;//是否有效
	
	private String description; ///图片描叙
	
	private String type;///图片类型
	
	private String url;//图片指定url地址
	
	private String layerOrder;//同城排序

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	public String getCreateId() {
		return createId;
	}

	public void setCreateId(String createId) {
		this.createId = createId;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public int getTimeLimit() {
		return timeLimit;
	}

	public void setTimeLimit(int timeLimit) {
		this.timeLimit = timeLimit;
	}

	public Organization getMerchant() {
		return merchant;
	}

	public void setMerchant(Organization merchant) {
		this.merchant = merchant;
	}

	public String getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(String isDelete) {
		this.isDelete = isDelete;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getLayerOrder() {
		return layerOrder;
	}

	public void setLayerOrder(String layerOrder) {
		this.layerOrder = layerOrder;
	}
	
	public String toString() {
		JSONObject obj = new JSONObject();
		
		obj.put("id", this.getId());
		obj.put("imageUrl", this.getImageUrl());
		obj.put("description", this.getDescription());
		obj.put("layerOrder", this.getLayerOrder());
		obj.put("merchant", this.getMerchant() == null ?"":this.getMerchant().getName());
		
		return obj.toString();
		
	}
}
